package com.lenovo.smarttraffic.Test.TestDragItem;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lenovo.smarttraffic.R;

import java.util.List;

/**
 * author  张猛
 **/


public class MesageAdapter extends RecyclerView.Adapter<MesageAdapter.Holder> {
    private Context mContext;
    private int position;
    private List<String> data;
    SwipeListLayout swipeListLayout;


    public MesageAdapter(Context mContext, List<String> data) {
        this.mContext = mContext;
        this.position = position;
        this.data = data;
    }

    public MesageAdapter(Context mContext, List<String> data,int position) {
        this.mContext = mContext;
        this.position = position;
        this.data = data;
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.test_item, parent, false);
        return new Holder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        holder.tv_name.setText(data.get(position));
        holder.tv_top.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                btnOnClickListen.onTopListen(holder.getLayoutPosition(), swipeListLayout);
                Log.e("position==", holder.getLayoutPosition() + "");
            }
        });
        holder.tv_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                btnOnClickListen.onDeleteListen(holder.getLayoutPosition(), swipeListLayout);
                Log.e("position==", holder.getLayoutPosition() + "");
            }
        });
        holder.ll_msg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(mContext, "正常区域", Toast.LENGTH_SHORT).show();
                Log.e("position==", holder.getLayoutPosition() + "");
            }
        });


    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class Holder extends RecyclerView.ViewHolder {
        TextView tv_delete, tv_top, tv_name;
        LinearLayout ll_msg;
        public Holder(View itemView) {
            super(itemView);
            tv_name = itemView.findViewById(R.id.tv_name);
            tv_delete = (TextView) itemView.findViewById(R.id.tv_delete);
            ll_msg = itemView.findViewById(R.id.ll_msg);
            tv_top = itemView.findViewById(R.id.tv_top);
            swipeListLayout=itemView.findViewById(R.id.sll_msg);
        }
    }





    public interface BtnOnClickListen {
        void onTopListen(int position, SwipeListLayout swipeListLayout);
        void onDeleteListen(int position, SwipeListLayout swipeListLayout);
    }
    /**
     * 点击，设置回调
     */
    public BtnOnClickListen btnOnClickListen;
    /**
     * 设置监听接口
     *
     * @param btnOnClickListen
     */
    public void setBtnOnClickListen(BtnOnClickListen btnOnClickListen) {
        this.btnOnClickListen = btnOnClickListen;
    }
}
